﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 订单管理系统窗体应用
{
    public partial class SearchForm : Form
    {
        List<Order> orders = new List<Order>();
        List<Order> searchOrders = new List<Order>();


        public SearchForm(List<Order> orders)
        {
            InitializeComponent();
            this.orders = orders;
        }

        private void SearchInID_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(InputText.Text))
            {
                MessageBox.Show("ID不能为空！");
            }
            else
            {
                int id = Convert.ToInt32(InputText.Text);
                var queryInId = from order in orders
                                where order.Id == id
                                orderby order.Money
                                select order;
                searchOrders = queryInId.ToList();
                ShowForm showForm = new ShowForm(searchOrders);
                showForm.ShowDialog();
            }
            
        }

        private void SearchInCustomer_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(InputText.Text))
            {
                MessageBox.Show("Customer不能为空！");
            }
            else
            {
                string customer = InputText.Text;
                var queryInCustomer = from order in this.orders
                                      where order.Customer == customer
                                      orderby order.Money
                                      select order;
                searchOrders = queryInCustomer.ToList();
                ShowForm showForm = new ShowForm(searchOrders);
                showForm.ShowDialog();
            }
        }

        private void SearchInMoneyMax_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(InputText.Text))
            {
                MessageBox.Show("Max Money不能为空！");
            }
            else
            {
                int max = Convert.ToInt32(InputText.Text);
                var queryInMoney = from order in this.orders
                               where order.Money <= max
                               orderby order.Money
                               select order;
                searchOrders = queryInMoney.ToList();
                ShowForm showForm = new ShowForm(searchOrders);
                showForm.ShowDialog();
            }
        }

        private void SearchInMoneyMin_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(InputText.Text))
            {
                MessageBox.Show("Min Money不能为空！");
            }
            else
            {
                int min = Convert.ToInt32(InputText.Text);
                var queryInMoney = from order in this.orders
                                   where order.Money >= min
                                   orderby order.Money
                                   select order;
                searchOrders = queryInMoney.ToList();
                ShowForm showForm = new ShowForm(searchOrders);
                showForm.ShowDialog();
            }
        }
    }
}
